class Main:
    res = []
    ans = []
    graph = [[] for _ in range(10001)]
    visited = [0] * 10001

    @staticmethod
    def dfs(u):
        if Main.visited[u] == 1:
            if Main.res and u in Main.res:
                while Main.res and Main.res[-1] != u:
                    Main.ans.append(Main.res.pop())
                Main.ans.append(u)
                Main.res.pop()
                return True
            else:
                return False

        Main.visited[u] = 1
        Main.res.append(u)
        for v in Main.graph[u]:
            if Main.dfs(v):
                return True
        Main.res.pop()
        return False

    @staticmethod
    def main():
        for i in range(10001):
            Main.graph[i] = []

        n = int(input())
        for _ in range(n):
            cur = list(map(int, input().split()))
            for val in cur[2:]:
                Main.graph[cur[1]].append(val)

        for i in range(10001):
            if Main.graph[i]:
                Main.dfs(i)

        last = Main.ans[-1]
        while Main.ans:
            print(Main.ans.pop(), end=" ")
        print(last)

if __name__ == "__main__":
    Main.main()